home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 203_01 / yam8.asm < prev    next >
Encoding:
Assembly Source File  |  1980-01-01  |  2.3 KB  |  77 lines

  1. TITLE YAM8: CRC SUBS
  2. PAGE 50,132
  3. ;DATE (24 jun 85)
  4. ;
  5. ;CRCK is a program to compute 
  6. ;a CYCLIC-REDUNDANCY-CHECK number based on the
  7. ;CCITT standard polynominal:
  8. ;   X^16 + X^15 + X^13 + X^7 + X^4 + X^2 + X + 1
  9. ;
  10. ;Useful for checking accuracy of file transfers.
  11. ;More accurate than a simple checksum.
  12. ;
  13. ;**************************************************
  14. ;
  15. ;           unsigned crck(buffer, bufsize, oldcrc)
  16. ;
  17. ;           At start of packet, oldcrc is set to 0
  18. ;
  19. ;           crc is accumulated by:
  20. ;                       oldcrc=crck(buffer, bufsize, oldcrc);
  21. ;
  22. ;           crck for file is final value of oldcrc
  23. ;
  24. ;           A Short Hostory of this function and crckfile() in yam7.c"
  25. ;
  26. ;           1.  First version used getc and called crck once per char.
  27. ;           this took 39.2 seconds to crck all the yam C files (12357)
  28. ;
  29. ;           2.  Then crckfile was recoded to use read() instead of getc.
  30. ;           Time: 19.1 seconds
  31. ;
  32. ;           3.  Several small changes in crckfile were unsuccessful in
  33. ;           reducing this time.
  34. ;
  35. ;           4.  crck and crckfile recoded to call crck once per sector.
  36. ;           This reduced time to 11.7 seconds, same as crck itself.
  37. ;           That is the current version.  Note that the CRC polynomial used
  38. ;           here is somewhat unusual; the only thing I know sure is that
  39. ;           the answers agree with those given by the CRCK program -hence the
  40. ;           function name.
  41. ;
  42.  
  43. ; SMALL MODEL
  44. INCLUDE \LC\S\DOS.MAC
  45.  
  46.     pseg
  47. public crck
  48. crck:
  49.     push    bp
  50.     mov    bp,sp
  51.     mov    bx,[bp+4]    ; get buffer pointer
  52.     mov    cx,[bp+6]    ; get buffer size
  53.     mov    dx,[bp+8]    ; get oldcrc
  54. ;
  55. ;---------------------------------------------
  56. ;Bsed on an 8080 routine for generating a
  57. ;CYCLIC-REDUNDANCY-CHECK by Fred Gutman.
  58. ;From 'EDN' magazine, June 5, 1979 issue, page 84.
  59. ;
  60. bytlop:
  61.     test    dh,80h        ; Q-bit mask
  62.     pushf                   ; save status
  63.     add    dx,dx        ; shl oldcrc
  64.     add    dl,[bx]        ; add byte from buffer
  65.     inc    bx        ; increment pointer to next byte
  66.     popf            ; retreive Q-bit status
  67.     jz    qb2        ; if Q-bit is zero
  68.     xor    dx,0A097h    ; gen. poly
  69. qb2:
  70.     loop    bytlop        ; do till buffer m-t
  71.     mov    ax,dx        ; answer in accumulator for return
  72.     pop    bp
  73.     ret
  74.  
  75.     endps
  76.         end
  77.